jQuery(document).ready(function() {
    //--------------------------------------- Variable defined ---------------------------------------
    //[Relocation Data] For Location/Site, city start
    var sel_relocation_type = 'edit-submitted-relocation-data-relocation-type'; //select id
    var V_pg_employee = 'pg_employee';
    var V_new_hire = 'new_hire';
    
    //var is_the_employee_yes = 'edit-submitted-relocation-data-is-the-employee-a-new-hire-1';//rodio id
    //var is_the_employee_no = 'edit-submitted-relocation-data-is-the-employee-a-new-hire-2';
    //document.getElementById(is_the_employee_no).checked ;
    
    var sending_site_div = 'webform-component-relocation-data--sending-work-location-site';
    var sending_site_input    = 'edit-submitted-relocation-data-sending-work-location-site';
    var sending_city_div     = 'webform-component-relocation-data--sending-work-city';
    var sending_city_input   = 'edit-submitted-relocation-data-sending-work-city';
    var please_specify_sending_div = 'webform-component-relocation-data--please-specify-sending';
    var please_specify_sending_input = 'edit-submitted-relocation-data-please-specify-sending';

    var receiving_site_div = 'webform-component-relocation-data--receiving-work-location-site';
    var receiving_site_input    = 'edit-submitted-relocation-data-receiving-work-location-site';
    var receiving_city_div     = 'webform-component-relocation-data--receiving-work-city';
    var receiving_city_input   = 'edit-submitted-relocation-data-receiving-work-city';
    var please_specify_receiving_div = 'webform-component-relocation-data--please-specify-receiving';
    var please_specify_receiving_input = 'edit-submitted-relocation-data-please-specify-receiving';
    var V_Others = 'Others';
 
    var company_code_id = 'edit-submitted-relocation-data-receiving-company-legal-entity2-code';
    var company_name_id = 'edit-submitted-relocation-data-receiving-company-legal-entity2-name';
    var company_city_id = 'edit-submitted-relocation-data-receiving-company-legal-entity2-city';
    var other_company_code_div = 'webform-component-relocation-data--company-code';
    var other_company_code_id = 'edit-submitted-relocation-data-company-code';
    var other_company_name_div = 'webform-component-relocation-data--company-name';
    var other_company_name_id = 'edit-submitted-relocation-data-company-name';
    //End
    
  
    //[Personal Data] For sap_id,pg_email,email start
    var global_sap_id_div = 'webform-component-personal-data--global-sap-id';
    var global_sap_id_input = 'edit-submitted-personal-data-global-sap-id';

    var pg_email_address_div = 'webform-component-personal-data--email-address';
    var pg_email_address_input = 'edit-submitted-personal-data-email-address';

    var email_address_div = 'webform-component-personal-data--email-address-2';
    var email_address_input = 'edit-submitted-personal-data-email-address-2';
    //End
    
    
    //[For Allowances Calculation] For hidden description & Is there a Salary change
    var allowances_calculation = 'webform-component-for-allowances-calculation--notice-for-allowances-calculation';
    var is_salary_change_description = 'webform-component-for-allowances-calculation--is-salary-change-description';

    //abc
    var sel_salary_change   = 'edit-submitted-for-allowances-calculation-is-salary-change';
    var V_Yes = 'Yes';
    
    var salary_change_date_div = 'webform-component-for-allowances-calculation--salary-change-date';
    var chage_day = 'edit-submitted-for-allowances-calculation-salary-change-date-day';
    var chage_month = 'edit-submitted-for-allowances-calculation-salary-change-date-month';
    var chage_year = 'edit-submitted-for-allowances-calculation-salary-change-date-year';
  
    //End
    
 
    //[P&G Initiator and Approver] For initiator role start
    var V_RLM = 'RLM';
    //var V_SLM = 'SLM';
    var sel_relocation_initiator = 'edit-submitted-pg-initiator-approver-relocation-initiator-role';
    var sel_as_approver_yes      = 'edit-submitted-pg-initiator-approver-is-relocation-initiator-acting-as-approver-1';
    var sel_as_approver_no       = 'edit-submitted-pg-initiator-approver-is-relocation-initiator-acting-as-approver-2';
  
    var linemanager_notice = 'webform-component-pg-initiator-approver--notice-display-line-manager';
    var linemanager_name   = 'webform-component-pg-initiator-approver--name-of-receiving-line-manager';
    var linemanager_email  = 'webform-component-pg-initiator-approver--receiving-line-manager-email';
    var approver_notice = 'webform-component-pg-initiator-approver--notice-display-approver';
    var approver_name   = 'webform-component-pg-initiator-approver--name-of-approver';
    var approver_email  = 'webform-component-pg-initiator-approver--approver-email';
    var approver_file   = 'webform-component-pg-initiator-approver--please-attach-approval-notification';
 
    var rlm_confirm     = 'webform-component-pg-initiator-approver--rlm-confirm-info';
    var not_rlm_confirm = 'webform-component-pg-initiator-approver--not-rlm-confirm-info';
    var rlm_checkbox_id     = 'edit-submitted-pg-initiator-approver-rlm-confirm-info-1';
    var not_rlm_checkbox_id = 'edit-submitted-pg-initiator-approver-not-rlm-confirm-info-1'; 
  
    var linemanager_name_input = 'edit-submitted-pg-initiator-approver-name-of-receiving-line-manager';
    var linemanager_email_input = 'edit-submitted-pg-initiator-approver-receiving-line-manager-email';
    
    // Fields to display only if Relocation Initiator is not Approver
    var approver_name_input = 'edit-submitted-pg-initiator-approver-name-of-approver';
    var approver_email_input = 'edit-submitted-pg-initiator-approver-approver-email';
    var approver_file_input = 'edit-submitted-pg-initiator-approver-please-attach-approval-notification-upload';
    //End
    //
    // 7 fields are not allowed to input number , costcenter
    var employee_last_name = 'edit-submitted-personal-data-employee-last-name';
    var employee_first_name = 'edit-submitted-personal-data-employee-first-name';
    var initiator_last_name = 'edit-submitted-pg-initiator-approver-initiator-last-name';
    var initiator_first_name = 'edit-submitted-pg-initiator-approver-initiator-first-name';
    //linemanager_name_input
    //approver_name_input
    var name_of_receiving_hr_manager = 'edit-submitted-pg-initiator-approver-name-of-receiving-hr-manager';
    var receiving_cost_centre= 'edit-submitted-relocation-data-receiving-cost-centre';
    
    //Additional Comments
    var additional_comments = 'edit-submitted-pg-initiator-approver-additional-comments';
    
    jQuery('#' + employee_last_name).addClass('english');
    jQuery('#' + employee_first_name).addClass('english');
    jQuery('#' + initiator_last_name).addClass('english');
    jQuery('#' + initiator_first_name).addClass('english');
    jQuery('#' + linemanager_name_input).addClass('english');
    jQuery('#' + approver_name_input).addClass('english');
    jQuery('#' + name_of_receiving_hr_manager).addClass('english');
    jQuery('#' + receiving_cost_centre).addClass('costcentre');
    
    jQuery('#' + please_specify_sending_input).addClass('english_comment');
    jQuery('#' + please_specify_receiving_input).addClass('english_comment');
    
    jQuery('#' + additional_comments).addClass('english_comment');

    //--------------------------------------- End variable defined ---------------------------------------


    //----------------------------------------- Event defined -----------------------------------------

    //[Relocation Data] Relocation Type
    jQuery('#'+sel_relocation_type).change(function() {
        //New Hire 
        if ( this.value == V_new_hire ) {
            set_mandatory(global_sap_id_div,global_sap_id_input,0);
            set_mandatory(pg_email_address_div,pg_email_address_input,0);
            set_display(email_address_div,email_address_input,1);
        }else {
            set_mandatory(global_sap_id_div,global_sap_id_input,1);
            set_mandatory(pg_email_address_div,pg_email_address_input,1);
            set_display(email_address_div,email_address_input,0);    
            if( this.value == '' ){
            }
        }
    });
    //End
    
    
    //[Relocation Data] Sending Location/City
    jQuery('#'+sending_city_input).change(function() {
        if ( this.value == V_Others ) {
            set_display(please_specify_sending_div,please_specify_sending_input,1);
        }else {
            set_display(please_specify_sending_div,please_specify_sending_input,0);
        }
    });
    //End
    
    //[Relocation Data] Receiving Location/City
    jQuery('#'+receiving_city_input).change(function() {
        if ( this.value == V_Others ) {
            set_display(please_specify_receiving_div,please_specify_receiving_input,1);
        }else {
            set_display(please_specify_receiving_div,please_specify_receiving_input,0);
        }
    });
    //End
    
    //abc
    //[For Allowances Calculation] For Is there a Salary change
    jQuery('#'+sel_salary_change).change(function() {
        if (this.value == V_Yes) {
            jQuery('#'+salary_change_date_div).fadeIn(0);
        }else {
            jQuery('#'+salary_change_date_div).fadeOut(0);
            jQuery('#'+chage_day).val('');
            jQuery('#'+chage_month).val('');
            jQuery('#'+chage_year).val('');
        }
    });
    //End
  


    //[P&G Initiator and Approver] For initiator role start
    jQuery('#'+sel_relocation_initiator).change(function() {
        // hide Confirm wordings before select Relocation Initiator Role
        if (this.value == '') {
            jQuery('#'+rlm_confirm).fadeOut(0);
            jQuery('#'+not_rlm_confirm).fadeOut(0);
          
            jQuery('#'+linemanager_name).fadeOut(0);
            jQuery('#'+linemanager_email).fadeOut(0);
          
            jQuery('#'+linemanager_name_input).val('');
            jQuery('#'+linemanager_name_input).removeClass('error');
            jQuery('#'+linemanager_name_input).parents("div:first").find("label.error").hide();
          
            jQuery('#'+linemanager_email_input).val('');
            jQuery('#'+linemanager_email_input).removeClass('error');
            jQuery('#'+linemanager_email_input).parents("div:first").find("label.error").hide();
        }else if (this.value != V_RLM) {
            //jQuery('#'+linemanager_notice).fadeIn(0);
            jQuery('#'+linemanager_name).fadeIn(0);
            jQuery('#'+linemanager_email).fadeIn(0);
	  
            jQuery('#'+rlm_confirm).fadeOut(0);
            jQuery('#'+not_rlm_confirm).fadeIn(0);
  
            document.getElementById(rlm_checkbox_id).checked = '';
            jQuery('#'+rlm_checkbox_id).removeClass("required");
            jQuery('#'+not_rlm_checkbox_id).addClass("required");
        }else {
            //jQuery('#'+linemanager_notice).fadeOut(0);
            jQuery('#'+linemanager_name).fadeOut(0);
            jQuery('#'+linemanager_email).fadeOut(0);
          
            jQuery('#'+linemanager_name_input).val('');
            jQuery('#'+linemanager_name_input).removeClass('error');
            jQuery('#'+linemanager_name_input).parents("div:first").find("label.error").hide();
          
            jQuery('#'+linemanager_email_input).val('');
            jQuery('#'+linemanager_email_input).removeClass('error');
            jQuery('#'+linemanager_email_input).parents("div:first").find("label.error").hide();
	  
            jQuery('#'+rlm_confirm).fadeIn(0);
            jQuery('#'+not_rlm_confirm).fadeOut(0);
          
            document.getElementById(not_rlm_checkbox_id).checked = '';
            jQuery('#'+not_rlm_checkbox_id).removeClass("required");
            jQuery('#'+rlm_checkbox_id).addClass("required");  
        }	
    });
    //End
    
    //[P&G Initiator and Approver] For Is Relocation Initiator acting as Approver?
    jQuery('#'+sel_as_approver_yes).change(function() {
        //jQuery('#'+approver_notice).fadeOut(0);
        jQuery('#'+approver_name).fadeOut(0);
        jQuery('#'+approver_email).fadeOut(0);
        jQuery('#'+approver_file).fadeOut(0);
	
        jQuery('#'+approver_name_input).val('');
        jQuery('#'+approver_name_input).removeClass('error');
        jQuery('#'+approver_name_input).parents("div:first").find("label.error").hide();
        
        jQuery('#'+approver_email_input).val('');
        jQuery('#'+approver_email_input).removeClass('error');
        jQuery('#'+approver_email_input).parents("div:first").find("label.error").hide();
        
        //jQuery('#'+approver_file_input).val('');
        jQuery('#'+approver_file_input).removeClass('error');
        jQuery('#'+approver_file_input).parents("div:first").find("label.error").hide();
        var file = jQuery(":file");
        file.after(file.clone().val(""));
        file.remove();

        jQuery('.messages.error').hide();
    });
    jQuery('#'+sel_as_approver_no).change(function() {
        //jQuery('#'+approver_notice).fadeIn(0);
        jQuery('#'+approver_name).fadeIn(0);
        jQuery('#'+approver_email).fadeIn(0);
        jQuery('#'+approver_file).fadeIn(0);
    });
    //End
    
    //[P&G Initiator and Approver] file upload onchange
    jQuery('#' + approver_file_input).live('change',function(){
        //console.log('change');
        if(jQuery('#edit-submitted-pg-initiator-approver-please-attach-approval-notification-ajax-wrapper').parent().find('div.messages').length){
            jQuery('#edit-submitted-pg-initiator-approver-please-attach-approval-notification-ajax-wrapper').parent().find('div.messages').remove();
        }
    });
    //End
    

    //------------------------------------------- End event defined ----------------------------------------
  
  

  
    //---------------------------- Display or hide field based on the value ---------------------------------
    var relocation_type_val = jQuery('#'+sel_relocation_type).val();
    //var is_the_employee_yes_val = document.getElementById(is_the_employee_yes).checked ;
    var sending_city_input_val = jQuery('#'+sending_city_input).val();
    var receiving_city_input_val = jQuery('#'+receiving_city_input).val();
    
    var sel_salary_change_val = jQuery('#'+sel_salary_change).val();
    
    
    //[Relocation Data] Relocation Type
    //New Hire
    if ( relocation_type_val == V_new_hire ) {
        set_mandatory(global_sap_id_div,global_sap_id_input,0);
        set_mandatory(pg_email_address_div,pg_email_address_input,0);
        set_display(email_address_div,email_address_input,1);
    }else {
        set_mandatory(global_sap_id_div,global_sap_id_input,1);
        set_mandatory(pg_email_address_div,pg_email_address_input,1);
        set_display(email_address_div,email_address_input,0);
        if( relocation_type_val == '' ){
        }
    }

    //[Relocation Data] Sending Location/City
    if ( sending_city_input_val == V_Others ) {
        set_display(please_specify_sending_div,please_specify_sending_input,1);
    }else {
        set_display(please_specify_sending_div,please_specify_sending_input,0);
    }

    //[Relocation Data] Receiving Location/City
    if ( receiving_city_input_val == V_Others ) {
        set_display(please_specify_receiving_div,please_specify_receiving_input,1);
    }else {
        set_display(please_specify_receiving_div,please_specify_receiving_input,0);
    }
   
    //[Relocation Data] Receiving Company/ Legal Entity:
    jQuery('#'+company_code_id).attr('readonly', 'readonly');
    jQuery('#'+company_name_id).attr('readonly', 'readonly');
    jQuery('#'+company_city_id).attr('readonly', 'readonly');
    if(jQuery('#edit-submitted-relocation-data-receiving-company-legal-entity2-code').val()!='0000'){
        set_display(other_company_code_div,other_company_code_id,0);
        set_mandatory(other_company_code_div,other_company_code_id,0);
        set_display(other_company_name_div,other_company_name_id,0);
    }
    //[Personal Data] SAP ID/Personnel Number
    jQuery('#'+global_sap_id_input).attr("maxlength","10");

    //[For Allowances Calculation] For hidden description & Is there a Salary change
    jQuery('#'+allowances_calculation).fadeOut(0);
    jQuery('#'+is_salary_change_description).fadeOut(0);
    if ( sel_salary_change_val == V_Yes ) {
        jQuery('#'+salary_change_date_div).fadeIn(0);
    }else {
        jQuery('#'+salary_change_date_div).fadeOut(0);
    }
  

    //[P&G Initiator and Approver] For hidden description
    jQuery('#'+linemanager_notice).fadeOut(0);
    jQuery('#'+approver_notice).fadeOut(0);

    //[P&G Initiator and Approver] Fields to display only if Relocation Initiator is not Receiving Line Manager
    if (jQuery('#'+sel_relocation_initiator).val() == '') {
        // hide Confirm wordings before select Relocation Initiator Role
        jQuery('#'+rlm_confirm).fadeOut(0);
        jQuery('#'+not_rlm_confirm).fadeOut(0);
    
        jQuery('#'+linemanager_name).fadeOut(0);
        jQuery('#'+linemanager_email).fadeOut(0);
    }else if (jQuery('#'+sel_relocation_initiator).val() != V_RLM) {
        //jQuery('#'+linemanager_notice).fadeIn(0);
        jQuery('#'+linemanager_name).fadeIn(0);
        jQuery('#'+linemanager_email).fadeIn(0);
	  
        jQuery('#'+rlm_confirm).fadeOut(0);
        jQuery('#'+not_rlm_confirm).fadeIn(0);    
        jQuery('#'+not_rlm_checkbox_id).addClass("required");    
    }else {
        //jQuery('#'+linemanager_notice).fadeOut(0);
        jQuery('#'+linemanager_name).fadeOut(0);
        jQuery('#'+linemanager_email).fadeOut(0);
	  
        jQuery('#'+rlm_confirm).fadeIn(0);
        jQuery('#'+not_rlm_confirm).fadeOut(0);
        jQuery('#'+rlm_checkbox_id).addClass("required");    
    }

  
    //[P&G Initiator and Approver] Is Relocation Initiator acting as Approver?
    if (document.getElementById(sel_as_approver_yes) && document.getElementById(sel_as_approver_yes).checked) {	  
        //jQuery('#'+approver_notice).fadeOut(0);
        jQuery('#'+approver_name).fadeOut(0);
        jQuery('#'+approver_email).fadeOut(0);
        jQuery('#'+approver_file).fadeOut(0);
    }
    if (document.getElementById(sel_as_approver_no) && document.getElementById(sel_as_approver_no).checked) {	  
        //jQuery('#'+approver_notice).fadeIn(0);
        jQuery('#'+approver_name).fadeIn(0);
        jQuery('#'+approver_email).fadeIn(0);
        jQuery('#'+approver_file).fadeIn(0);
    }
    //---------------------------- End display or hide field based on the value ---------------------------------

  
    // ------------------Handel the logic for form reset button click-----------------------------
    var edit_reset = 'edit-reset';
    jQuery('#'+edit_reset).click(function() {
        var relocation_type_val = jQuery('#'+sel_relocation_type).val();
        //var is_the_employee_yes_val = document.getElementById(is_the_employee_yes).checked ;
        var sending_city_input_val = jQuery('#'+sending_city_input).val();
        var receiving_city_input_val = jQuery('#'+receiving_city_input).val();
        
        var sel_salary_change_val = jQuery('#'+sel_salary_change).val();

        if ( relocation_type_val == V_new_hire ) {
            set_mandatory(global_sap_id_div,global_sap_id_input,0);
            set_mandatory(pg_email_address_div,pg_email_address_input,0);
            set_display(email_address_div,email_address_input,1);
        }else { 
            set_mandatory(global_sap_id_div,global_sap_id_input,1);
            set_mandatory(pg_email_address_div,pg_email_address_input,1);
            set_display(email_address_div,email_address_input,0);
            if( relocation_type_val == '' ){
            }
        }

        //[Relocation Data] Sending Location/City
        if ( sending_city_input_val == V_Others ) {
            set_display(please_specify_sending_div,please_specify_sending_input,1);
        }else {
            set_display(please_specify_sending_div,please_specify_sending_input,0);
        }

        //[Relocation Data] Receiving Location/City
        if ( receiving_city_input_val == V_Others ) {
            set_display(please_specify_receiving_div,please_specify_receiving_input,1);
        }else {
            set_display(please_specify_receiving_div,please_specify_receiving_input,0);
        }
        //Receiving Company/Legal Entity
        set_display(other_company_code_div,other_company_code_id,0);
        set_mandatory(other_company_code_div,other_company_code_id,0);
        set_display(other_company_name_div,other_company_name_id,0);
        //[For Allowances Calculation] For Is there a Salary change
        if ( sel_salary_change_val == V_Yes ) {
            jQuery('#'+salary_change_date_div).fadeIn(0);
        }else {
            jQuery('#'+salary_change_date_div).fadeOut(0);
        }
       
       //[P&G Initiator and Approver] Fields to display only if Relocation Initiator is not Receiving Line Manager
        if (jQuery('#'+sel_relocation_initiator).val() == '') {
            jQuery('#'+rlm_confirm).fadeOut(0);
            jQuery('#'+not_rlm_confirm).fadeOut(0);
            
            jQuery('#'+linemanager_name).fadeOut(0);
            jQuery('#'+linemanager_email).fadeOut(0);
            
            jQuery('#'+linemanager_name_input).removeClass('error');
            jQuery('#'+linemanager_name_input).parents("div:first").find("label.error").hide();
            jQuery('#'+linemanager_email_input).removeClass('error');
            jQuery('#'+linemanager_email_input).parents("div:first").find("label.error").hide();
        }else if (jQuery('#'+sel_relocation_initiator).val() != V_RLM) {
            jQuery('#'+linemanager_name).fadeIn(0);
            jQuery('#'+linemanager_email).fadeIn(0);
            
            jQuery('#'+linemanager_name_input).removeClass('error');
            jQuery('#'+linemanager_name_input).parents("div:first").find("label.error").hide();
            jQuery('#'+linemanager_email_input).removeClass('error');
            jQuery('#'+linemanager_email_input).parents("div:first").find("label.error").hide();
	  
            jQuery('#'+rlm_confirm).fadeOut(0);
            jQuery('#'+not_rlm_confirm).fadeIn(0);    
            jQuery('#'+not_rlm_checkbox_id).addClass("required");    
        }else {
            jQuery('#'+linemanager_name).fadeOut(0);
            jQuery('#'+linemanager_email).fadeOut(0);
	  
            jQuery('#'+rlm_confirm).fadeIn(0);
            jQuery('#'+not_rlm_confirm).fadeOut(0);
            jQuery('#'+rlm_checkbox_id).addClass("required");    
        }
        
        if (document.getElementById(sel_as_approver_yes) && document.getElementById(sel_as_approver_yes).checked) {	  
            //jQuery('#'+approver_notice).fadeOut(0);
            jQuery('#'+approver_name).fadeOut(0);
            jQuery('#'+approver_email).fadeOut(0);
            jQuery('#'+approver_file).fadeOut(0);
        }
        if (document.getElementById(sel_as_approver_no) && document.getElementById(sel_as_approver_no).checked) {	  
            //jQuery('#'+approver_notice).fadeIn(0);
            jQuery('#'+approver_name).fadeIn(0);
            jQuery('#'+approver_email).fadeIn(0);
            jQuery('#'+approver_file).fadeIn(0);
            
            jQuery('#'+approver_name_input).removeClass('error');
            jQuery('#'+approver_name_input).parents("div:first").find("label.error").hide();
            jQuery('#'+approver_email_input).removeClass('error');
            jQuery('#'+approver_email_input).parents("div:first").find("label.error").hide();
            
            jQuery('#'+approver_file_input).removeClass('error');
            jQuery('#'+approver_file_input).parents("div:first").find("label.error").hide();
            jQuery('.messages.error').hide();
        
        }
    });
    //-----------------------------------------------End----------------------------------------------

    //Validate start
    // This function just run after 'Remove' the upload file!
    var check_file_upload = function(){
        if (document.getElementById(sel_as_approver_yes) && document.getElementById(sel_as_approver_yes).checked) {
            return true;
        }
        // must upload file before submit form
        //var upload_error = ...(defined in webform_common.js)
        if(jQuery('#'+approver_file_input).length && jQuery('#'+approver_file_input).val()){
            var error = '<label id="upload-file-error" for="'+approver_file_input+'" generated="true" class="error" style="display: block;">'+ upload_error + '</label>';
            if(!(jQuery('#upload-file-error').length)){
                jQuery("#edit-submitted-pg-initiator-approver-please-attach-approval-notification").append(error);
            }
            else{
                jQuery('#upload-file-error').show();
            }
		      
            if(!jQuery('#'+approver_file_input).hasClass('error')){
                jQuery('#'+approver_file_input).addClass('error');			 
            }
            //jQuery('#'+approver_file_input).focus();
            return false;
        }
        return true;
    };
    
    var chageSelectDay = jQuery('#'+chage_day).change(function() {
        if (jQuery('#'+chage_day).val() == '') {
            chageSelectDay.valid();
        }
    });
    var chageSelectMonth = jQuery('#'+chage_month).change(function() {
        if (jQuery('#'+chage_month).val() == '') {
            chageSelectMonth.valid();
        }
    });
    var chageSelectYear = jQuery('#'+chage_year).change(function() {
        if (jQuery('#'+chage_year).val() == '') {
            chageSelectYear.valid();
        }
    });
    //Validate set start
    jQuery.validator.addMethod("default_date", function(value, element) {
        if( (jQuery('#'+chage_day).val() =='' && jQuery('#'+chage_month).val() =='' && jQuery('#'+chage_year).val()=='') || (jQuery('#'+chage_day).val() !='' && jQuery('#'+chage_month).val() !='' && jQuery('#'+chage_year).val()!='') ){
            jQuery('#'+chage_day).removeClass('error');
            jQuery('#'+chage_month).removeClass('error');
            jQuery('#'+chage_year).removeClass('error')
            return true;
        }else{
            jQuery('#'+chage_day).addClass('error');
            jQuery('#'+chage_month).addClass('error');
            jQuery('#'+chage_year).addClass('error');
            return false;
        }
    });
    //end Validate set

    jQuery(".webform-client-form").validate({
        submitHandler: function(form){
            if(check_file_upload()){
                form.submit();
            }else{
                return false;
            }
        },
        groups:{
            date:"submitted[relocation_data][relocation_effective_date][day] submitted[relocation_data][relocation_effective_date][month] submitted[relocation_data][relocation_effective_date][year]",
            search:"submitted[relocation_data][receiving_company_legal_entity2][code] submitted[relocation_data][receiving_company_legal_entity2][name] submitted[relocation_data][receiving_company_legal_entity2][city]",
            myphone:"submitted[personal_data][phone_work][country] submitted[personal_data][phone_work][area] submitted[personal_data][phone_work][phone] submitted[personal_data][phone_work][ext]",
            mymobile:"submitted[personal_data][mobile_work][country] submitted[personal_data][mobile_work][mobile]",
            relocation_phone:"submitted[pg_initiator_approver][relocation_initiator_phone_][country] submitted[pg_initiator_approver][relocation_initiator_phone_][area] submitted[pg_initiator_approver][relocation_initiator_phone_][phone] submitted[pg_initiator_approver][relocation_initiator_phone_][ext]",
            receiving_hr_phone:"submitted[pg_initiator_approver][receiving_hr_manager_phone][country] submitted[pg_initiator_approver][receiving_hr_manager_phone][area] submitted[pg_initiator_approver][receiving_hr_manager_phone][phone] submitted[pg_initiator_approver][receiving_hr_manager_phone][ext]",
            change_date:"submitted[for_allowances_calculation][salary_change_date][day] submitted[for_allowances_calculation][salary_change_date][month] submitted[for_allowances_calculation][salary_change_date][year]"
        },
        errorPlacement:function(error,element) {  
            if ( element.attr("name") == "submitted[relocation_data][relocation_effective_date][day]" || element.attr("name") == "submitted[relocation_data][relocation_effective_date][month]" || element.attr("name") == "submitted[relocation_data][relocation_effective_date][year]")  
                error.insertAfter("#edit-submitted-relocation-data-relocation-effective-date-year"); 
            else if ( element.attr("name") == "submitted[relocation_data][receiving_company_legal_entity2][code]" || element.attr("name") == "submitted[relocation_data][receiving_company_legal_entity2][name]" || element.attr("name") == "submitted[relocation_data][receiving_company_legal_entity2][city]")  
                error.insertAfter("#ctools-ajax-sample-button"); 
            else if ( element.attr("name") == "submitted[personal_data][phone_work][country]" || element.attr("name") == "submitted[personal_data][phone_work][area]" || element.attr("name") == "submitted[personal_data][phone_work][phone]" || element.attr("name") == "submitted[personal_data][phone_work][ext]")  
                error.insertAfter("#edit-submitted-personal-data-phone-work-ext");  
            else if (element.attr("name") == "submitted[personal_data][mobile_work][country]" || element.attr("name") == "submitted[personal_data][mobile_work][mobile]" )  
                error.insertAfter("#edit-submitted-personal-data-mobile-work-mobile");
            else if (element.attr("name") == "submitted[pg_initiator_approver][relocation_initiator_phone_][country]" || element.attr("name") == "submitted[pg_initiator_approver][relocation_initiator_phone_][area]" 
                ||  element.attr("name") == "submitted[pg_initiator_approver][relocation_initiator_phone_][phone]" || element.attr("name") == "submitted[pg_initiator_approver][relocation_initiator_phone_][ext]")  
                error.insertAfter("#edit-submitted-pg-initiator-approver-relocation-initiator-phone-ext");
            else if (element.attr("name") == "submitted[pg_initiator_approver][receiving_hr_manager_phone][country]" || element.attr("name") == "submitted[pg_initiator_approver][receiving_hr_manager_phone][area]" 
                ||  element.attr("name") == "submitted[pg_initiator_approver][receiving_hr_manager_phone][phone]" || element.attr("name") == "submitted[pg_initiator_approver][receiving_hr_manager_phone][ext]")  
                error.insertAfter("#edit-submitted-pg-initiator-approver-receiving-hr-manager-phone-ext");
            else if (element.attr("name") == "submitted[for_allowances_calculation][salary_change_date][day]" || element.attr("name") == "submitted[for_allowances_calculation][salary_change_date][month]" 
                ||  element.attr("name") == "submitted[for_allowances_calculation][salary_change_date][year]")  
                error.insertAfter("#edit-submitted-for-allowances-calculation-salary-change-date-year");
            else if (element.attr("id") == "edit-submitted-pg-initiator-approver-additional-comments"){
                error.insertAfter("#webform-component-pg-initiator-approver--additional-comments .grippie");
            }else
                error.insertAfter(element);
        }
	
    });
    //End validate
});